package com.example.zhunongzonghe.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.zhunongzonghe.beans.ZnCollectHouseBean;
import com.example.zhunongzonghe.beans.ZnFarmhouseBean;
import com.example.zhunongzonghe.common.Result;
import com.example.zhunongzonghe.service.ZnCollectHouseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.security.Principal;

@RestController
@RequestMapping("/ZnCollectHouse")
public class ZnCollectHouseController {
    @Resource
    private ZnCollectHouseService collectHouseService;

    /**
     * 用户收藏农家乐
     * @param znCollectHouseBean
     * @return
     */
    @RequestMapping("/addCollectHouse")
    public Result postCollectFarm(@RequestBody ZnCollectHouseBean znCollectHouseBean, Principal principal){
        if (znCollectHouseBean.getHouseId() == null) return new Result(false,"数据异常",400);
        collectHouseService.addCollect(znCollectHouseBean,principal.getName());
        return new Result(true,"收藏成功",200);
    }

    /**
     * 分页查询当前用户的农产品收藏
     * @param principal
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/getMyCollects")
    public Result getMyCollects(Principal principal,
                                @RequestParam("currentPage") Integer currentPage,
                                @RequestParam("pageSize") Integer pageSize){
        Page<ZnFarmhouseBean> collectPostBeanPage =
                collectHouseService.MyCollects(principal.getName(),currentPage,pageSize);
        return new Result(true,"成功",200,collectPostBeanPage);
    }
}
